package munci.old.know.words;

import munci.old.know.Env;
import munci.old.use.Tokens;

public class Constant extends Word {
	
	private final Object value;
	private final Class<?> type;

	public Constant(String name, Object value) {
		this(name, value, value.getClass());
	}

	public Constant(String name, Object value, Class<?> type) {
		super(name);
		this.value = value;
		this.type = type;
	}

	public boolean execute(Env env) {
		if (env.compiling()) {
			env.stack.push(new Tokens().add(name), Tokens.class);
		} else {
			env.stack.push(value, type);
		}
		return true;
	}

	@Override public String toString() {
		return super.toString() + " constant: " + value;
	}
}
